function Front() 
{
	this.brand_id = '';

	//===== 首页 ======//
	// 通过省id获取城市2
	this.get_city2 = function(province,city)
	{
		//直辖市 北，上，重，天
		var municipality = new Array(5034,5035,5036,5037);
		var current_city = 0; 

		$.post('/utility/get_city_list',
			{
				province :  province
			},
			function(o){

				if(o){
					var opt='<option value="">请选择</option>';
					for(i=0; i<o.length; i++)
					{
						var selected='';
						if(city==o[i].id)
						{
							selected = 'selected="selected"';
						}
						else
						{
							for(j=0; j<municipality.length; j++)
							{
								if(o[i].id == municipality[j])
								{
									selected = 'selected="selected"';
									current_city = municipality[j];
									break;
								}
							}
						}
						opt += '<option value="' + o[i].id + '" ' + selected + '>' + o[i].name + '</option>';
					}
					$("#select_city option").remove(); 
					$("#select_city").append(opt); 

					$("#select_county option").remove(); 
					$("#select_shangquan option").remove(); 
					$("#select_mall option").remove(); 
				}

				if(current_city>0)
					front.get_county_list(current_city);
			},
			'json'
		);
	},

	//通过市ID 获取区列表
	this.get_county_list = function(city)
	{
		$.get('/utility/get_county_list/'+city,
			{
			},
			function (o) {

				if(o){
					var opt='<option value="">请选择</option>';
					for(i=0; i<o.length; i++)
					{
						var selected='';
						if(city == o[i].id)
						{
							selected = 'selected="selected"';
						}
						opt += '<option value="' + o[i].id + '" ' + selected + '>' + o[i].name + '</option>';
					}

					$('#select_county option').remove();
					$('#select_county').append(opt);

					$('#select_shangquan option').remove();
					$('#select_mall option').remove();
				}
			},
			'json'
		);
	},

	//通过区ID 获取商圈列表
	this.get_shangquan_list = function(county)
	{
		$.get('/utility/ajax_shangquan/'+county,
			{
			},
			function (o) {

				if(o){
					var opt='<option value="">请选择</option>';
					for(i=0; i<o.length; i++)
					{
						var selected='';
						if(county == o[i].id)
						{
							selected = 'selected="selected"';
						}
						opt += '<option value="' + o[i].id + '" ' + selected + '>' + o[i].name + '</option>';
					}
					$('#select_shangquan option').remove();
					$('#select_shangquan').append(opt);

					$('#select_mall option').remove();
				}
			},
			'json'
		);
	},

	//通过商圈ID 获得卖场列表
	this.get_mall_list = function (shangquan)
	{
		$.get('/utility/ajax_mall/'+shangquan,
			{},
			function(o){
				
				if(o) {
					var opt='<option value="">请选择</option>';
					for(i=0; i<o.length; i++)
					{
						var selected='';
						if(shangquan == o[i].id)
						{
							selected = 'selected="selected"';
						}
						opt += '<option value="' + o[i].id + '" ' + selected + '>' + o[i].name + '</option>';
					}
					$('#select_mall option').remove();
					$('#select_mall').append(opt);
				}
			},
			'json'
		);
	},

/*----------------------------入驻申请---start---------------------------*/

	//入驻申请首页，选择商铺类型
	this.apply_type = function(type)
	{
		if(type == 'flagship')
		{
			window.location.href = '/merchantapply/apply/1';
		}
		else if(type == 'exclusive')
		{
			window.location.href = '/merchantapply/apply/2';
		}
		else if(type == 'boutique')
		{
			window.location.href = '/merchantapply/apply/3';	
		}
		else
		{
			return false;
		}
	}


	//入驻申请，显示登陆搜狐passport账号
	this.show_login_passport = function()
	{
		$('.passport_error_tip').hide();
		$('#userid').val('');
		$('#password').val('');
		$('#login_passport').slideToggle("slow"); 
	}


	//入驻申请，检查登陆搜狐passport账号
	this.login_passport_check = function()
	{
		var userid		= $('#userid').val();
		var password	= $('#password').val();

		var flag = 1;
		if(userid == '')
		{
			$('#userid').parent().find('.tip').html('<span class="check-err">不能为空，请填写！</span>'); 
			flag = 0;
		}
		else
		{
			$('#userid').parent().find('.tip').html('<span class="check-ok"></span>'); 
		}


		if(password == '')
		{
			$('#password').parent().find('.tip').html('<span class="check-err">不能为空，请选择！</span>'); 
			flag = 0;
		}
		else
		{
			$('#password').parent().find('.tip').html('<span class="check-ok"></span>'); 
		}
		
		if(flag == 1)
			return true;
		else
			return false;
	}



	//获取某一级系统分类
	this.change_catesys = function(that,oj,level,te)
	{
		var brand_level = level; 
		var value = $(that).val();
		if(value == 0 || value == '')
		{
			return false;
		}

		front.last_cate = 0;
        $.get('/utility/sys_category/'+ value,
			{
				//province :  province
			},
			function(o){
				if(o){
					if(o.length > 1 && level >= 2)
					{
						alert("OK");
						level = level+1;
						for(var i=level; i<5; i++)
						{
							$(that).parents('.frm').find('.category_sys_'+i).remove();
						}

						obj = '.brand';
						var wrap1 = "<select onchange=\"front.get_brand(this, '"+obj+"' ,"+level+")\" class='category_sys_"+level+"' style='width:100px;margin-right:10px' name='category_sys_"+level+"'>"
						
						var wrap2 = "</select>"
						var opt='<option value="">请选择</option>';
						for(i=0; i<o.length; i++)
						{
							opt += '<option value="' + o[i].id + '">' + o[i].cate_name + '</option>';
						}
						var oSelect = wrap1 + opt + wrap2
						$(that).parents('.frm').append(oSelect); 
					}
					else
					{
						for(var i=3; i<5; i++)
						{
							$(that).parents('.frm').find('.category_sys_'+i).remove();
						}

						var opt='<option value="">请选择</option>';
						for(i=0; i<o.length; i++)
						{
							opt += '<option value="' + o[i].id + '">' + o[i].cate_name + '</option>';
						}
						$(that).parents('.frm').find(oj).html(opt); 
						if(te)
							$(that).parents('.frm').find('.tip').html('<span class="check-ok"></span>'); 
						
						if(level == 2 && o.length < 1 )
						{
							var str = '<select name="category_sys_3" class="category_sys_3" style="display:none;"><option value="">请选择</option></select>';
							$(that).parents('.frm').append(str);
						}
						
					}
				}
				
			},
			'json'
		);

		if(brand_level > 1)
		{
			setTimeout(function(){
				front.get_brand(that, '.brand', brand_level);
			},500)
		}
	}

	//获取品牌（某一级分类下的）
	this.get_brand = function(that,oj,level)
	{

		var value = $(that).val();
		if(value == 0 || value == '')
		{
			if(level > 2)
			{
				level=level-1;
				value = $(that).prev().val();
			}
			else
			{
				return false;
			}
		}
        $.get('/utility/get_brand/'+ value + '/' + level,
			{
				//province :  province
			},
			function(o){
				if(o){
					var opt='<option value="">请选择</option>';
					for(i=0; i<o.length; i++)
					{
						opt += '<option value="' + o[i].id + '">' + o[i].name + '</option>';
					}
					$(that).parents('.brand_main').find(oj).html(opt); 
				}
			},
			'json'
		);
	}

	
	//选择一个品牌
	this.select_brand = function(that)
	{
		var iVal = $(that).val();
		if(iVal == '' || iVal == 0)
		{
			$(that).parent().find('.tip').html('<span class="check-err">经营品牌不能为空！</span>');
		}
		else
		{
			$(that).parent().find('.tip').html('<span class="check-ok"></span>'); 
		}
	}


	//增加一个品牌内容项
	this.add_brand_html = function()
	{
		
		var shop_type = $('#shop_type').val();

		if(shop_type == 1 || shop_type == 2)
		{
			if(!confirm('品牌旗舰店（专卖店）不能经营多个品牌，为了贵店可以顺利通过审核，请确认上传的多种品牌为同一品牌下的子品牌!'))
				return false;	
		}

		var brand_init = $('.brand_init').html();
		$('.brand_new_add').append(brand_init); 
	}

	//删除当前品牌内容
	this.delete_curr_brand_html = function(that)
	{
		$(that).parents('.brand_main').remove();
	}

	//表单即时验证
	this.form_verify = function(that)
	{
		//如果当前对象是身份证的号单独处理
		if($(that).attr('id') == 'jperson_document_number')
		{
			var jperson_document_type	= $('#jperson_document_type').val();
			var jperson_document_number = $('#jperson_document_number').val();
			if(jperson_document_type == 1)
			{
				var reg_sfz = /^[0-9]{14,17}[0-9a-zA-Z]{1}$/;
				if(reg_sfz.test(jperson_document_number))
				{
					$('#jperson_document_number').parent().find('.tip').html('<span class="check-ok"></span>');
				}
				else
				{
					$('#jperson_document_number').parent().find('.tip').html('<span class="check-err">身份证号有误，请重新填写！</span>'); 
					flag = 0;
				}
			}
		}
		else
		{
			var iVal = $(that).val();
			if(iVal == '' || iVal == 0)
			{
				$(that).parent().find('.tip').html('<span class="check-err">不能为空，请填写或选择！</span>');
			}
			else
			{
				$(that).parent().find('.tip').html('<span class="check-ok"></span>'); 
			}
		}

	}

	//检查行业分类
	this.form_verify_hangye = function(that)
	{
		var cate3 = $('.major_category_3').val();
		var cate2 = $('.major_category_2').val();
		var len = $('.major_category_3').find('option').length;
		if(len > 1){
			if(cate3 == '')
				$(that).parent().find('.tip').html('<span class="check-err">不能为空，请填写或选择！</span>');
			else
				$(that).parent().find('.tip').html('<span class="check-ok"></span>'); 
		}
		else
		{
			if(cate2 == '')
				$(that).parent().find('.tip').html('<span class="check-err">不能为空，请填写或选择！</span>');
			else
				$(that).parent().find('.tip').html('<span class="check-ok"></span>');
		}
	}
	
	//手机和电话可选一项
	this.form_verify_mobile = function(that)
	{
		
		var iId = $(that).attr('id');
		if(iId == 'phone')
		{
			var phone = $('#phone').val();
			if(phone != '')
			{
				var reg_phone = /^[0-9]{2}[0-9-]{9,11}$/
				if(reg_phone.test(phone))
				{
					$('#phone').parent().find('.tip').html('<span class="check-ok"></span>');
					var mobile = $('#mobile').val();
					if(mobile != '')
					{
						var reg_mobile = /^1[0-9]{10}$/
						if(reg_mobile.test(mobile))
						{
							$('#mobile').parent().find('.tip').html('');
						}
					}
					else
					{
						$('#mobile').parent().find('.tip').html('');
					}
				}
				else
				{
					$('#phone').parent().find('.tip').html('<span class="check-err">联系电话有误，正确格式如：010-62728466</span>'); 
					return false;
				}
			}
		}
		else if(iId == 'mobile')
		{
			var mobile = $('#mobile').val();
			if(mobile != '')
			{
				var reg_mobile = /^1[0-9]{10}$/
				if(reg_mobile.test(mobile))
				{
					$('#mobile').parent().find('.tip').html('<span class="check-ok"></span>');
				}
				else
				{
					$('#mobile').parent().find('.tip').html('<span class="check-err">手机号码有误，正确格式为：15001381383</span>'); 
					return false;
				}
			}
			else
			{
				var phone = $('#phone').val();
				var reg_phone = /^[0-9]{2}[0-9-]{9,11}$/
				if(reg_phone.test(phone))
				{
					$('#mobile').parent().find('.tip').html('');
				}	
			}
		}

		

	}


	//显示上传经营资质
	this.show_business_upload = function(that)
	{
		//使层跟随当前对象显示左下角位置
		var y=this.posOffset(that).top + that.offsetHeight + 5;
		var x=this.posOffset(that).left - 140;
			
		$('#box_business').css({
			'left'	:	x+'px',
			'top'	:	y+'px'
		});
		$('#box_business').show();
	}

	//显示上传店铺实景图
	this.show_shopimg_upload = function(that)
	{
		//使层跟随当前对象显示左下角位置
		var y=this.posOffset(that).top + that.offsetHeight + 5;
		var x=this.posOffset(that).left - 140;
			
		$('#box_shopimg').css({
			'left'	:	x+'px',
			'top'	:	y+'px'
		});
		
		$('#box_shopimg').show();
	}

	//显示上传品牌授权
	this.show_brands_upload = function(that)
	{
		var shop_type = $('#shop_type').val();
		if(shop_type == 1 || shop_type == 2)
		{
			if($('#brands_div_all').children("div").length >= 1)
			{	
				if(!confirm('品牌旗舰店（专卖店）不能经营多个品牌，为了贵店可以顺利通过审核，请确认上传的多种品牌为同一品牌下的子品牌!'))
					return false;
			}
		}

		//使层跟随当前对象显示左下角位置
		var y=this.posOffset(that).top + that.offsetHeight + 5;
		var x=this.posOffset(that).left - 130;
			
		$('#box_brands').css({
			'left'	:	x+'px',
			'top'	:	y+'px'
		});
		
		$('#box_brands').show();
	}

	/*
	 *判断上传文件是否为图像（.jpg .gif .png）
	 *
	 *参数obj为类名(.className)或是ID名(#idName) 如 id="aa" 那么obj="#aa" 如 class="aa" 那么 obj='.aa';
	 */
	this.check_upload_image = function(obj,form_name)
	{
		var sFile = $(obj).val();
		var iPosition = parseInt(sFile.lastIndexOf('.'))+1;
		var extensionName = sFile.substring(iPosition,sFile.length);
		
		if(extensionName != 'jpg' && extensionName != 'JPG' && extensionName != 'png' && extensionName != 'PNG' && extensionName != 'jpeg' && extensionName != 'JPEG' && extensionName != 'gif' && extensionName != 'GIF')
		{
			alert('上传失败，请检查上传文件的类型为图片格式如: .jpg、.gif、.png类型，并且图片大小请限制在2M以内！');
			return false;
		}

		if(form_name != '')
		{
			var form    = document.forms[form_name];
			return upimage.image_upload_ready(form);
		}

		return true;
	}

	this.check_upload_image2 = function(obj)
	{
		var sFile = $(obj).val();
		if(sFile != '')
		{
			var iPosition = parseInt(sFile.lastIndexOf('.'))+1;
			var extensionName = sFile.substring(iPosition,sFile.length);
			
			if(extensionName != 'jpg' && extensionName != 'JPG' && extensionName != 'png' && extensionName != 'PNG' && extensionName != 'jpeg' && extensionName != 'JPEG' && extensionName != 'gif' && extensionName != 'GIF')
			{
				return false;
			}
		}
		return true;
	}


	//删除品牌授权的某一个图片
	this.submit_del_brand_img = function(id)
	{
		if(confirm('您确认删除吗？删除后不可恢复！') == false)
		{
			return ;
		}

		$.get("/merchantapply/del_brand_img/"+id,
			{
			},
			function (o) {
				if(o.status)
				{
					$('#del_brand_div_'+id).remove();
				}
				else
				{
					alert('失败！');
				}
			},
			'json'
			);
			return;
	}
	
	// 协议事件
	this.submit_tiaokuan = function(o){
		if(o.checked){
			$(o).parent().next().show();
		}else{
			$(o).parent().next().hide();
		}
	},


	//提交表单并验证
	this.submit_apply = function(oj)
	{
		var shop_name = $('#shop_name'),
			select_province = $('#select_province'),
			select_city		= $('#select_city'),
			address			= $('#address'),
			name			= $('#name'),
			mobile			= $('#mobile'),
			tiaokuan        = $('#tiaokuan'),
			flag            = 1;
		
		// shop name
		if(shop_name.val() == '' || shop_name.val().length > 20){
			shop_name.addClass('error').parent().next().show();
			flag = 0;
		}else{
			shop_name.removeClass('error').parent().next().hide();
		}
		
		// 店铺区域
		if(select_province.val() == '' || select_city.val() == null || select_city.val() == ''){
			select_province.parent().next().show();
			flag = 0;
		}else{
			select_province.parent().next().hide();
		}
		
		
		// shop address
		if(address.val() == '' || address.val().length > 30){
			address.addClass('error').parent().next().show();
			flag = 0;
		}else{
			address.removeClass('error').parent().next().hide();
		}
		
		// shop name
		if(name.val() == '' || name.val().length > 5){
			name.addClass('error').parent().next().show();
			flag = 0;
		}else{
			name.removeClass('error').parent().next().hide();
		}

		// shop mobile
		if(mobile.val() == '' || !mobile.val().match(/^\d{11}$/)){
			mobile.addClass('error').parent().next().show();
			flag = 0;
		}else{
			mobile.removeClass('error').parent().next().hide();
		}
		
		if(flag == 0)
			return false;
		return true;
	}



/*----------------------------我的收藏---start---------------------------*/
	
	//增加收藏
	this.add_favorite = function(itemid,type)
	{
		if (current_merchant_id > 0 || 
			(current_merchant_id <= 0 && current_user_id <= 0))
		{
			passportMgr.check(null, true, null);
			return false;
		}

		$.get('/my/myfavorite/add_collection/'+itemid+'/'+type,
			{
			},
			function(o){
				if(o.status){
					alert(o.message);
					return ;
				}
				else
				{
					alert(o.message);
					return ;
				}
			},
			'json'
		);
	}

	//收藏(价格排序)
	this.sort_price= function(type)
	{
		if(type == '')
			return false

		var url = window.location.href;
		var iIndex = url.indexOf('?');

		if(iIndex<0)
		{
			url = url+'?sort_price_type='+type;
		}
		else
		{
			url = url.substring(0,iIndex);
			url = url+'?sort_price_type='+type;
		}

		top.location = url;
	}


	//收藏(时间排序)
	this.sort_time= function(type)
	{
		if(type == '')
			return false

		var url = window.location.href;
		var iIndex = url.indexOf('?');

		if(iIndex<0)
		{
			url = url+'?sort_time_type='+type;
		}
		else
		{
			url = url.substring(0,iIndex);
			url = url+'?sort_time_type='+type;
		}

		top.location = url;
	}

	//删除收藏
	this.delete_favorite= function(id)
	{
		if(parseInt(id) <= 0)
			return false;

		var url = window.location.href;

		$.get('/my/myfavorite/remove/'+id,
			{
			},
			function(o){
				if(o.state)
				{
					top.location = url;
				}
				else
				{
					alert(o.tip);
				}
			},
			'json'
		);
	}

/*----------------------------增加收藏---over---------------------------*/




/*----------------------------商铺街---start----------------------------*/

	//提交商品分类1
	this.street_categroy1 = function(id)
	{
		$('#cate1_id').val(id);
		this.street_condition();
	}

	//提交商品分类2
	this.street_categroy2 = function(id)
	{
		$('#cate2_id').val(id);
		this.street_condition();
	}

	//商铺街筛选条件处理
	this.street_condition = function(condition)
	{

		var shop_province	= $('#select_province').val();
		var shop_city		= $('#select_city').val();
		var cate1_id		= $('#cate1_id').val();
		var cate2_id		= $('#cate2_id').val();
		var btype1          = '';
		var btype2          = '';
		var btype3          = '';

		if($('#brand_type1').attr('checked'))
			btype1 = 1;

		if($('#brand_type2').attr('checked'))
			btype2 = 1;

		if($('#brand_type3').attr('checked'))
			btype3 = 1;

		var condition = 'cate1_id='+cate1_id+'&cate2_id='+cate2_id+'&shop_province='+shop_province+'&shop_city='+shop_city+'&brand_type1='+btype1+'&brand_type2='+btype2+'&brand_type3='+btype3;
		top.location = '/brands?'+condition;
	}




/*----------------------------商铺街---over----------------------------*/
	
/*-------------------------商铺搜索页---start--------------------------*/

	//提交商品分类1
	this.shops_categroy1 = function(id)
	{
		$('#cate1_id').val(id);
		this.shops_condition();
	}

	//提交商品分类2
	this.shops_categroy2 = function(id)
	{
		$('#cate2_id').val(id);
		this.shops_condition();
	}

	//商铺街筛选条件处理
	this.shops_condition = function(condition)
	{

		var shop_province	= $('#select_province').val();
		var shop_city		= $('#select_city').val();
		var cate1_id		= $('#cate1_id').val();
		var cate2_id		= $('#cate2_id').val();
		var kword           = encodeURIComponent($('#kword').val());
		var btype1          = '';
		var btype2          = '';
		var btype3          = '';

		if($('#kword').val() == '搜索词')
			kword = '';

		if($('#brand_type1').attr('checked'))
			btype1 = 1;

		if($('#brand_type2').attr('checked'))
			btype2 = 1;

		if($('#brand_type3').attr('checked'))
			btype3 = 1;
		
		var condition = 'kword='+kword+'&cate1='+cate1_id+'&cate='+cate2_id+'&shop_province='+shop_province+'&shop_city='+shop_city+'&brand_type1='+btype1+'&brand_type2='+btype2+'&brand_type3='+btype3;
		top.location = '/s/shops?'+condition;
	}
	
/*-------------------------商铺搜索页---end----------------------------*/	

/*----------------------------公用的---start----------------------------*/	
	
	//调转页
	this.go_page = function(url)
	{
		var page = $('#page_number').val();
		if(url)
		{
			var url  = url+'&page='+page;
			top.location = url;
		}
		else
		{
			var url = window.location.href;
			var iIndex1 = url.indexOf('?');
			var iIndex2 = url.indexOf('page');

			if(iIndex1<0)
			{
				url = url+'?page='+page;
			}
			else if(iIndex1>0 && iIndex2<0)
			{
				url = url+'&page='+page;
			}
			else if(iIndex1>0 && iIndex2>0)
			{
				
				url = url.substring(0,iIndex2);
				url = url+'page='+page;
			}
			top.location = url;
		}
		
		return false;
	}


	//初始化时为空
	this.init_empty = function(that)
	{
		$(that).find('input').val('');
		$(that).find('textarea').val('');
	},


	//清空当前内容
	this.empty = function(that)
	{
		that.value = '';
		that.innerHTML = '';
	},


	//显示对象位置坐标(X,Y)
	this.posOffset = function (el)
	{
		var offset = {left:0,top:0};
		while(el){
			offset.left += el.offsetLeft;
			offset.top += el.offsetTop;
			el = el.offsetParent;
		}
		return offset;
	}


/*----------------------------公用的---over----------------------------*/	

/*----------------------------商家后台 start----------------------------*/	

	//显示--修改我的发货信息
	this.update_send_goods_info = function(that)
	{
		var y=this.posOffset(that).top + that.offsetHeight + 5;
		var x=this.posOffset(that).left - 400;
			
		$('#send_goods_info').css({
			'left'	:	x+'px',
			'top'	:	y+'px'
		});
		
		$('#send_goods_info').show();
	}


	//显示--修改我的退货信息 
	this.update_refund_goods_info = function(that)
	{
		var y=this.posOffset(that).top + that.offsetHeight + 5;
		var x=this.posOffset(that).left - 400;
			
		$('#refund_goods_info').css({
			'left'	:	x+'px',
			'top'	:	y+'px'
		});
		
		$('#refund_goods_info').show();
	}


	//关闭物流修改信息层
	this.close_logistics_info_box = function(that)
	{
		$(that).parent().hide();
	}


	//选择不同的发货，收货地址
	this.select_logistics_address = function(that,obj)
	{
		var contactName	= $(that).parent().parent().find('.contactName').html();
		var showAddress	= $(that).parent().parent().find('.showAddress').html();
		var zipCode		= $(that).parent().parent().find('.zipCode').html();
		var tel			= $(that).parent().parent().find('.tel').html();
		var mobile		= $(that).parent().parent().find('.mobile').html();
		
		var allHtml = '';
		if(showAddress != '')
			allHtml += showAddress + '，';
		if(zipCode != '')
			allHtml += zipCode + '，';
		if(contactName != '')
			allHtml += contactName + '，';
		if(tel != '')
			allHtml += tel + '，';
		if(mobile != '')
			allHtml += mobile;

		$('.select_address_box').hide();
		if(obj == 'send')
		{
			$('input[name="send_address"]').val(allHtml);
			$('.buyers-receive-info').html(allHtml);
		}
		else if(obj == 'refund')
		{
			$("input[name='refund_address']").val(allHtml);
			$('.refund-address-info').html(allHtml);
		}
	}



	
	//发货管理中----选择其它隐藏的物流公司
	this.show_more_logistics_company = function(that)
	{
		if( $('#moreHiddenCompany').attr('class') != '' )
		{
			$(that).parents('.logistics-company').find('#moreHiddenCompany').attr('class','');
			$(that).html('隐藏其他物流公司');
		}
		else
		{
			$(that).parents('.logistics-company').find('#moreHiddenCompany').attr('class','more-hidden-company');
			$(that).html('显示其他物流公司');
		}
	}


	//清空备注内容
	this.empty_info = function(that)
	{
		var currStr = that.value;
		if(currStr.indexOf('您可以在此输入') != -1)
		{
			that.value = '';
		}
	}

	//最大文字不能超过250个字符
	this.max_text_250 = function (that)
	{
		var currStr = that.value;
		if(currStr.length > 250)
		{
			alert('不能超过250个字符!');
		}
	}


	//选择物流服务的提交表单
	this.submit_logistics_service_form = function(that)
	{
		var order_id			= $('#order_id').val();
		var memo				= $('#memo').val();
		var send_address		= $('#send_address').val();
		var refund_address		= $('#refund_address').val();
		var logistics_company	= $(that).parent().parent().find('.logistics_company').val();
		var logistics_number	= $(that).parent().parent().find('.logistics_number').val();

		var post_url			= '/consign/send_goods';

		var formTop		= '<form name="save_logistics_form" method="POST" action="'+post_url+'" id="save_logistics_form" style="display:none;">';
		var formBottom	= '</form>';

		if(logistics_company == '' || logistics_number == '')
		{
			alert('请检查物流公司名称和物流单号是否填写完整!');
			return false
		}

		var yd_number = /^[a-zA-Z0-9_-]{4,32}$/;
		if(!yd_number.test(logistics_number))
		{
			alert('运单号格式错误！');
			return false;
		}


		if(memo.indexOf('您可以在此输入备忘信息') != -1)
			memo = '';

		var form_order_id			= '<div>我的订单号：<input type="text" value="'+order_id+'" name="order_id"></div>';
		var form_memo				= '<div>我的备忘：<input type="text" value="'+memo+'" name="memo"></div>';
		var form_send_address		= '<div>卖家发货地址：<input type="text" value="'+send_address+'" name="send_address"></div>';
		var form_refund_address		= '<div>卖家的退货地址：<input type="text" value="'+refund_address+'" name="refund_address"></div>';
		var form_logistics_company	= '<div>物流公司名称：<input type="text" value="'+logistics_company+'" name="logistics_company"></div>';
		var form_logistics_number	= '<div>物流单号：<input type="text" value="'+logistics_number+'" name="logistics_number"></div>';


		var form_html = formTop + form_order_id + form_memo + form_send_address + form_refund_address + form_logistics_company + form_logistics_number + formBottom;

		$('body').append(form_html);

		setTimeout(function () {
			var form = document.forms['save_logistics_form'];
			form.submit();
		}, 100);
	
	}


/*----------------------------商家后台 end----------------------------*/

}




/*------------商铺---商品详情--分享 mikewang add 2010-10-26 ----------*/	
function Share() 
{
	var obj = this;
	//商品分享层 -- 显示
	this.show_goods_share = function(that)
	{

		var oShare = document.getElementById('gpopup-goods-share');
		var y=this.posOffset(that).top + that.offsetHeight + 5;
		var x=this.posOffset(that).left;
			
		oShare.style.display = 'block';
		/*
		oShare.style.left = x+'px';
		oShare.style.top = y+'px';
		

		oShare.style.left = (this.viewWidth() - oShare.offsetWidth)/2 + 'px';
		oShare.style.top = (this.viewHeight() - oShare.offsetHeight)/2 + 'px';

		*/
	}


	//商品分享层 -- 关闭
	this.close_goods_share = function(that)
	{
		var oShare = document.getElementById('gpopup-goods-share');
		oShare.style.display = 'none';
	}

	//商品分享层 -- 初如化内容 
	this.init = function(that)
	{
		var sTitle = that.value;
		if(sTitle.indexOf('宝贝好不好? 和大家说两句吧') != -1)
		{
			that.value='';
		}
	}


	//选择分享目标
	this.select_share = function(that,type)
	{
		var sTarget = document.getElementById('goods-share-target');
		var iShareList = document.getElementById('shareList');
		var aType = iShareList.getElementsByTagName('label');
		for(var i=0; i<aType.length; i++)
		{	
			var type = aType[i].getElementsByTagName('i')[0].className;
			type = type.replace(/i-/,'');
			
			aType[i].type = type;
			aType[i].index = i;
			aType[i].onclick = function()
			{
				for(i=0; i<aType.length; i++)
				{
					var sClassName = aType[i].className
					if(sClassName.indexOf('selected') != -1)
					{
						re = /selected/g;
						aType[i].className = sClassName.replace(re, '');  
					}
				}

				aType[this.index].className = this.type+" selected";
				sTarget.value = this.type;
			}
		}
	}


	//分享标题 -- 更新
	this.update_share_title = function(that)
	{
		var sTitle = document.getElementById('share-title-container');
		var sTitleNew = document.getElementById('edit-share-title-container');

		
		sTitleNew.value = sTitle.innerHTML;

		if(sTitleNew.style.display == 'none')
		{
			sTitle.style.display = 'none';
			sTitleNew.style.display = 'block';
		}
		else
		{
			sTitle.style.display = 'block';
			sTitleNew.style.display = 'none';
		}
	}

	//分享标题 -- 保存
	this.save_share_title = function(that)
	{
		var sTitle = document.getElementById('share-title-container');
		var sTitleNew = document.getElementById('edit-share-title-container');

		sTitle.innerHTML = sTitleNew.value;
		sTitle.style.display = 'block';
		sTitleNew.style.display = 'none';
	}



	//属标移开内容为空时 -- 显示初如化内容 
	this.init_check = function(that)
	{
		var sTitle = that.value;
		if(sTitle == '')
		{
			that.value='宝贝好不好? 和大家说两句吧...';
		}
	}

	//icon图片 -- 属标移上/移开
	this.over_share = function(that,type)
	{
		var iShareList = document.getElementById('shareList');
		var aType = iShareList.getElementsByTagName('label');
		for(var i=0; i<aType.length; i++)
		{	
			var type = aType[i].getElementsByTagName('i')[0].className;
			type = type.replace(/i-/,'');
			
			
			aType[i].type = type;
			aType[i].onmouseover = function()
			{
				obj.show_share_tip(this.type);	
			}

			aType[i].onmouseout = function()
			{
				var sTip = document.getElementById('share-popup');
				sTip.style.display = 'none';
			}
		}
	}


	//显示分享按钮提示
	this.show_share_tip = function(type)
	{
		if(type != '')
		{
			var sTipText	= '';
			var sLeft		= '';
			var y			= '82px';

			switch(type)
			{
				case 'sohu':
					sTipText= '搜狐微博';
					sLeft	= '107px';
					break;
				case 'sina':
					sTipText= '新浪微博';
					sLeft	= '134px';
					break;
				case 'tencent':
					sTipText= '腾讯微博';
					sLeft	= '158px';
					break;
				case 'renren':
					sTipText= '人人网';
					sLeft	= '184px';
					break;
				case 'douban':
					sTipText= '豆瓣';
					sLeft	= '209px';
					break;
				case 'qzone':
					sTipText= 'QQ空间';
					sLeft	= '234px';
					break;
				case 'kaixin':
					sTipText= '开心网';
					sLeft	= '259px';
					break;
				case 'bsh':
					sTipText= '白社会';
					sLeft	= '285px';
					break;

				default:
					alert('请选择我们提供的分享类型!');
			}

			var sTip		= document.getElementById('share-popup');
			var sTipInfo	= document.getElementById('share-tip-info');
			var sTipText	= '点击后分享到' + sTipText;
			
			sTip.style.display = 'block';
			sTip.style.top	= y;
			sTip.style.left	= sLeft;
			sTipInfo.innerHTML = sTipText;
		}
	}


	//分享 -- 提交
	this.goods_share_submit = function()
	{
		var sTarget = document.getElementById('goods-share-target').value;
		var sTitle	= document.getElementById('goods-share-title').value;

		if(sTitle.indexOf('宝贝好不好? 和大家说两句吧') != -1)
			sTitle = '';
		
		var sContent= document.getElementById('share-title-container').innerHTML;
		var sPrice	= document.getElementById('goods-share-price').innerHTML;
		var sPic	= document.getElementById('goods-share-pic').src;

		var share_title		= sTitle + ' ' + sContent + ' ' + sPrice + ' ';
		var share_url		= window.location.href;
		var share_pic		= sPic;
		
		
		var oShare = document.getElementById('gpopup-goods-share')
		oShare.style.display = 'none';


		if(!sTarget)
		{
			alert('请选择你要分享的类型。是搜狐微博、新浪微博、人人、开心网、腾讯微薄、豆瓣、QQ空间还是白社会!');
		}


		var url = '';
		var target = '';
		switch(sTarget)
		{
			case 'sohu':
				url	= "javascript:void((function(s,d,e,r,l,p,t,z,c){var f='http://t.sohu.com/third/post.jsp?',u=z||d.location,p=['&url=',e(u),'&title=',e(t||d.title),'&content=',c||'gb2312','&pic=',e(p||'')].join('');function a(){if(!window.open([f,p].join(''),'mb',['toolbar=0,status=0,resizable=1,width=660,height=470,left=',(s.width-660)/2,',top=',(s.height-470)/2].join('')))u.href=[f,p].join('');};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else a();})(screen,document,encodeURIComponent,'','','"+share_pic+"','"+share_title+"','"+share_url+"','utf-8'))";
				target = '_self';
				break;
			case 'kaixin':
				url = "http://www.kaixin001.com/repaste/share.php?rurl="+share_url+"&rtitle="+encodeURIComponent(share_title)+"&rcontent="+share_url;
				target = '_blank';
				break;
			case 'renren':
				url = "http://share.renren.com/share/buttonshare/post/1004?title="+encodeURIComponent(share_title)+"&content="+share_url+"&pic="+share_pic+"&url="+share_url;
				target = '_blank';
				break;
			case 'sina':
				url	= "javascript:void((function(s,d,e,r,l,p,t,z,c){var%20f='http://v.t.sina.com.cn/share/share.php?appkey=1130613470',u=z||d.location,p=['&url=',e(u),'&title=',e(t||d.title),'&source=',e(r),'&sourceUrl=',e(l),'&content=',c||'gb2312','&pic=',e(p||'')].join('');function%20a(){if(!window.open([f,p].join(''),'mb',['toolbar=0,status=0,resizable=1,width=440,height=430,left=',(s.width-440)/2,',top=',(s.height-430)/2].join('')))u.href=[f,p].join('');};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();})(screen,document,encodeURIComponent,'','','"+share_pic+"','"+share_title+"','"+share_url+"','utf-8'))";
				target = '_self';
				break;
			case 'tencent':
				url	= "http://v.t.qq.com/share/share.php?title="+encodeURIComponent(share_title)+"&url="+share_url+"&appkey=51d04b4824744e71bd1e55baceb42562&pic="+share_pic;
				target = '_blank';
				break;
			case 'douban':
				url = "http://shuo.douban.com/!service/share?image="+share_pic+"&href="+share_url+"&name="+encodeURIComponent(share_title);
				target = '_blank';
				break;
			case 'qzone':
				url	= "http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?title="+encodeURIComponent(share_title)+"&url="+share_url+"&pics="+share_pic;
				target = '_blank';
				break;
			case 'bsh':
				url	= "http://bai.sohu.com/share/blank/addbutton.do?from=ihome&link="+share_url;
				target = '_blank';
				break;

			default:
				alert('请选择我们提供的分享类型!');
		}


		var shareSumit = document.getElementById('share-sumit');
		shareSumit.href = url;
		shareSumit.target = target;
		return true;
		
	}
	
	//显示对象位置坐标(X,Y)
	this.posOffset = function(el)
	{
		var offset = {left:0,top:0};
		while(el)
		{
			offset.left += el.offsetLeft;
			offset.top	+= el.offsetTop;
			el = el.offsetParent;
		}
		return offset;
	}

	this.viewWidth = function(){
		return document.documentElement.clientWidth;
	}

	this.viewHeight = function(){
		return document.documentElement.clientHeight;
	}

	this.documentHeight = function(){
		return Math.max(document.documentElement.scrollHeight || document.body.scrollHeight,document.documentElement.clientHeight);
	}
	
	this.scrollY = function(){
		return document.documentElement.scrollTop || document.body.scrollTop;
	}
}

var share = new Share();

function limitImages(obj,maxWidth,maxHeight)
{
	if(obj == '' || maxWidth == '' || maxHeight == '')
	{
		alert('请输入有效的参数，依次是obj、maxWidth和maxHeight!')
	}
	var aImg=obj.getElementsByTagName("img");
	var i=0;
	for(i=0;i<aImg.length;i++)
	{
		if(aImg[i].offsetWidth > maxWidth)
		{
			aImg[i].style.width = maxWidth + "px";
		}
		if(aImg[i].offsetHeight > maxHeight)
		{
			if(aImg[i].style.width)
			{
				aImg[i].style.width="";
			}
			aImg[i].style.height = maxHeight + "px";
		}
	}
}


/*-------------商铺---导航条目--浮动层  mikewang add 2010-11-15 -------------*/	

function StoreCategories(){

	this.iPageList = 10; //每页显示菜单个数
	
	//导航条目--分页(菜单初始化)
	this.fcategories_page = function(){
		var oCateList = $('.fCate-list > .fcate');
		var iCateLen = oCateList.length;
		var pageCount = Math.ceil(iCateLen/this.iPageList);
		var iPageList = this.iPageList;
		var i = 0;

		this.showPageCate(1);
		if(iCateLen > iPageList){
			this.addPage(pageCount);			
		}
	}
	

	//导航条目---显示XX页的菜单分类
	this.showPageCate = function(page){

		if(page == ''){
			page = 1;
		}
		var oCateList = $('.fCate-list > .fcate');
		var iCateLen = oCateList.length;
		var iPageList = this.iPageList;
		var iStart	= parseInt(iPageList*(page-1));
		var iEnd	= parseInt(page*iPageList-1);

		$('.fcate-page .fpager li').removeClass('active');
		$('.fcate-page .fpager li').eq(page-1).addClass('active');

		oCateList.hide();
		
		for(var i=iStart; i<=iEnd; i++){

			oCateList.eq(i).show();
		}
	}


	//导航条目--根据菜单个数--自动增加分页
	this.addPage = function(Len){
		var sul_header	= '<ul class="fpager" >';
		var sul_footer	= '</ul>';
		var sli			= '';
		for(var i=1; i<=Len; i++)
		{
			if(i==1)
				sli += '<li class="active" onclick="fStoreCategories.showPageCate('+(i)+');">'+i+'</li>';
			else
				sli += '<li onclick="fStoreCategories.showPageCate('+(i)+');">'+i+'</li>';
		}

		var oul = sul_header + sli + sul_footer;
		$('.fcate-page').append(oul);
	}

	//导航条目---显示二级菜单效果
	this.fcategories_over = function(){
		$('.fCate-list > .fcate').each(function(){
			
			this.onmouseover = function(){
				$(this).children('div').css({'display'	: 'block'});
			}

			this.onmouseout = function(){
				$(this).children('div').css({'display'	: 'none'});
			}
		})
	}

	//导航条目收缩
	this.hide_fcategories = function(){
		var fCategories = document.getElementById('fCategories');
		if(fCategories.className == 'fCategories')
		{
			fCategories.className = 'fCategories_hide';
		}else{
			fCategories.className = 'fCategories';
		}
	}

	
	//返回到顶部
	this.goTop = function(){
		document.documentElement.scrollTop = document.body.scrollTop = 0;
	}

}




/*-------------商铺---显示更多商品属性  mikewang add 2010-11-21 -------------*/	

function MoreAttr(){
	$('#more-attr-list .inner a').click(function(){
		if($(this).attr('class')=='open'){
			$('.property-sort .fgoods-s-attr-list:gt(2)').show();
			$(this).attr('class','close');
			$(this).find('span').html('收起');
		}else{
			$('.property-sort .fgoods-s-attr-list:gt(2)').hide();
			$(this).attr('class','open');
			$(this).find('span').html('显示全部分类');
		}
	})

}



/** 垃圾代码 *****/
/*-----------下订单时给商家留言 mikewang add 2010-12-09 -------------*/	

function BuyMessage(){

	//下单给商家留言时,在Input 和 Textarea 之间切换模式
	this.change_order_message = function(){
		var sMessage1 = document.getElementById('order_message_input');
		var sMessage2 = document.getElementById('change_order_message');
		sMessage1.onclick = function()
		{
			if(sMessage1.value.indexOf('选填') != -1)
			{
				sMessage1.value = '';
			}
			sMessage2.value = '';
			sMessage2.value = sMessage1.value;
			sMessage1.style.display = 'none';
			sMessage2.style.display = 'block';
		}
		sMessage2.onblur = function()
		{
			sMessage1.value = sMessage2.value;
			if(sMessage2.value.length > 300)
			{
				$('.buy_message_tip').html('你的留言不能超过300个字符!');
			}
			else
			{
				$('.buy_message_tip').html('');
			}

			sMessage1.style.display = 'block';
			sMessage2.style.display = 'none';
			
			if(sMessage2.value == '')
			{
				sMessage1.value = '选填，可以告诉卖家您对商品的特殊要求，如：颜色等';
			}
		}

	}
	
	//提交前检测试留言长度(不超过300字符)
	this.test_message_length = function()
	{
		var iCount = 300;
		var sAlreadyMessage = document.getElementById('already_message');
		var sNewMessage		= document.getElementById('new_message');
		var sTip			= document.getElementById('message-tip');
		var iNewCount		=  sAlreadyMessage.innerHTML.length + sNewMessage.value.length;
		if(iNewCount > iCount)
		{
			var i = iNewCount-iCount;
			sTip.innerHTML = "已超出 "+i+" 个字符!";
			return false;
		}
		else
		{
			sTip.innerHTML = "";
		}
	}

	this.edit_message = function (btn)
	{
		var show = $('#already_message');
		var box  = $('#message-edit-box');

		if ($(btn).html() == '编辑留言')
		{
			show.hide();
			box.show();
			$(btn).html('取消编辑');
			//box.find('textarea').val(show.html());
		}
		else
		{
			show.show();
			box.hide();
			$(btn).html('编辑留言');
		}
	}

	this.submit_order_message = function (btn)
	{
		var msg = $(btn).prev().val();
		var order_id = $(btn).prev().prev().val();
		var url = '/message/ajax_order';
		if (msg.length > 300 || msg.length < 4)
		{
			alert('订单留言字数限制在4~300个字符内，请检查');
			return false;
		}

		$.post(url, { 
				'order_id' : order_id, 
				'order_message' : msg 
			}, function (o) {

				if (o.status == 0)
				{
					alert('留言成功！');
					$('#already_message').html(o.content);
					message_op.edit_message($('.forder-message .edit-btn'));
				}
		}, 'json');
	}

}
